<%@ page contentType="text/html; charset=gb2312" pageEncoding="GBK"%>
<%@ page
	import="scsc.pub.db.DBManage,java.sql.*"%>
<%@ page import="scsc.pm.SysTaskItem"%>
<%@ page import="scsc.pub.exception.UnifyUserException"%>
<%String mTaskInstanceId = request.getParameter("taskInstanceId");
			String mTaskItemInstanceId = request
					.getParameter("taskItemInstanceId");
			String isFirst = "";

			String mRecordID = request.getParameter("RecordID");
			if (mRecordID == null)
				mRecordID = "";
			String mTemplate = request.getParameter("Template");
			String mSubject = request.getParameter("Subject");
			String mAuthor = request.getParameter("Author");
			String mFileDate = request.getParameter("FileDate");
			String mFileType = request.getParameter("FileType");
			String mHTMLPath = request.getParameter("HTMLPath");
			String mStatus = "READ";

			DBManage dbmanage = new DBManage();
			SysTaskItem taskItem = new SysTaskItem();
			dbmanage.begin();
			try {
				taskItem.isDone(dbmanage, new Long(mTaskItemInstanceId));
				dbmanage.commit();
			} catch (UnifyUserException e) {
				dbmanage.rollback();
			}

			Connection conn = null;
			Statement stmt = null;
			ResultSet result = null;
			java.sql.PreparedStatement prestmt = null;
			try {
				if (dbmanage.getSession().isConnected()) {
					String mysql = "SELECT RecordID from  Document Where RecordID='"
							+ mRecordID + "'";
					String sqlStr = "";
					try {
						conn = dbmanage.getSession().connection();
						stmt = conn.createStatement();
						result = stmt.executeQuery(mysql);
						if (result.next()) {
							mysql = "update Document set RecordID=?,Template=?,Subject=?,Author=?,FileDate=?,FileType=?,HtmlPath=?,Status=? where RecordID='"
									+ mRecordID + "'";
							isFirst = "0";
						} else {
							mysql = "insert into Document (RecordID,Template,Subject,Author,FileDate,FileType,HtmlPath,Status) values (?,?,?,?,?,?,?,?)";
							isFirst = "1";
						}
					} catch (Exception e) {
						System.out.println(e.toString());
					}
					try {
						prestmt = conn.prepareStatement(mysql);
						prestmt.setString(1, mRecordID);
						prestmt.setString(2, mTemplate);
						prestmt.setString(3, mSubject);
						prestmt.setString(4, mAuthor);
						prestmt.setString(5, mFileDate);
						prestmt.setString(6, mFileType);
						prestmt.setString(7, mHTMLPath);
						prestmt.setString(8, "READ");

						conn.setAutoCommit(false);
						prestmt.executeUpdate();
						conn.commit();

					} catch (Exception e) {
						conn.rollback();
						System.out.println(e.toString());
					}
				} else {
					out.println("OpenDatabase Error");
				}
			} finally {
				try {
					result.close();
					stmt.close();
					prestmt.close();
					dbmanage.close();
				} catch (Exception e) {
					System.out.println(e.toString());
				}
			}
			response.sendRedirect("/process.do?operAtt=edit&taskInstanceId="+mTaskInstanceId);

		%>
